// index.js
// 获取应用实例
const app = getApp()
const api = require("../config/app")
Page({
  //初始化数据
  data: {
    "imgSrcs": [
      {
        "img": "https://i.postimg.cc/Nf8zL9vc/a.jpg",
        "text": "1"
      },  
      {
        "img": "https://i.postimg.cc/VLzFGKpx/b.jpg",
        "text": "2"
      },
      {
        "img": "https://i.postimg.cc/rwmNcK8g/c.png",
        "text": "3"
      },
      {
        "img": "https://i.postimg.cc/qv5X74qr/d.png",
        "text": "4"
      },
      {
        "img": "https://i.postimg.cc/d188nCBQ/e.png",
        "text": "5"
      },
      {
        "img": "https://i.postimg.cc/1RrGqpXJ/f.png",
        "text": "6"
      }
    ],
    "lists": [
      {
        "id": "1",
        "image": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner1.png",
        "title": "保障性租赁住房政策解读及融资实操分享",
        "num": "304",
        "state": "进行中",
        "starttime": "2022-03-13 00:00:00",
        "location": "深圳市·南山区"
      },
      {
        "id": "2",
        "image": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner2.png",
        "title": "城建领域的项目谋划方向与资金筹措方式探讨",
        "num": "380",
        "state": "已结束",
        "starttime": "2022-03-15 00:00:00",
        "location": "北京市·朝阳区"
      },
      {
        "id": "3",
        "image": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner3.png",
        "title": "221118保障性租赁住房技术培训",
        "num": "500",
        "state": "进行中",
        "starttime": "2022-03-13 00:00:00",
        "location": "大连市"
      },
      // {
      //   "id": "4",
      //   "image": "/static/persons/4.jpg",
      //   "title": "报名年度盛事，大咖云集！2016凤凰国际论坛邀您“与世界对话”",
      //   "num": "150",
      //   "state": "已结束",
      //   "starttime": "2022-03-13 00:00:00",
      //   "location": "北京市·朝阳区"
      // },
      // {
      //   "id": "5",
      //   "image": "/static/persons/5.jpg",
      //   "title": "新质生活 · 品质时代 2016消费升级创新大会",
      //   "num": "217",
      //   "state": "进行中",
      //   "starttime": "2022-03-13 00:00:00",
      //   "location": "北京市·朝阳区"
      // }
    ],
    lists1:[
      {
        "id": "4",
        "image": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner4.png",
        "title": "以旧换新”政策分析及业务要点分享",
        "num": "150",
        "state": "已结束",
        "starttime": "2022-03-13 00:00:00",
        "location": "北京市·朝阳区"
      },
      {
        "id": "5",
        "image": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner5.png",
        "title": "城市生命线安全工程政策汇编",
        "num": "217",
        "state": "进行中",
        "starttime": "2022-03-13 00:00:00",
        "location": "北京市·朝阳区"
      }
    ]
  }, "statusCode": "200",
  "header": {
    "content-type": "applicaiton/json;charset=utf-8"
  },
  // 事件处理函数
  // 获取轮播图的方法
  loadSwiperImgs() {
    let that = this;
    wx.request({
      url: api.SwiperImgs,
      dataType: 'json',
      success(res) {
        console.log(res)
        // that.setData({
        //     imgSrcs:res.data.images
        // })
      }
    })
  },
  //  获取首页会议信息的方法
  loadMeetingInfos() {
    let that = this;
    wx.request({
      url: api.MettingInfos,
      dataType: 'json',
      success(res) {
        console.log(res)
        that.setData({
          lists: res.data.lists
        })
      }
    })
  },
  onLoad() {
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
    this.loadSwiperImgs();
  },
  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log("------:" + res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },
  getUserInfo(e) {
    // 不推荐使用getUserInfo获取用户信息，预计自2021年4月13日起，getUserInfo将不再弹出弹窗，并直接返回匿名的用户个人信息
    console.log(e)
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  tapView(event) {
    console.log('点击事件:' + JSON.stringify(event.currentTarget.dataset.items));
    wx.navigateTo({
      url: '/pages/logs/logs',
    })
  },
  imgView(event) {
    console.log('点击事件:' + JSON.stringify(event.currentTarget.dataset.item));
    const img = event.currentTarget.dataset.item.img;
    let url = '/pages/introduce/introduce?img=' + img;
    if (event.currentTarget.dataset.item.text === '1') {
      url = '/pages/introduce/introduce?img=' + img
    }
    wx.navigateTo({
      url: url,
    })
  },
  showBusiness() {
    // console.log("接口："+ wx.getStorageSync('token'))
    // wx.request({
    //   url: api.SwiperImgs,
    //   header: {
    //     'Content-Type': 'application/json',
    //     'X-Access-Token':  wx.getStorageSync('token')
    //   },
    //   success(res) {
    //     console.log("test:"+JSON.stringify(res))
    //     // that.setData({
    //     //     imgSrcs:res.data.images
    //     // })
    //   }
    // })
    wx.navigateTo({
      url: "/pages/businessIntroduction/business",
    })
  },
  showCourse() {
    wx.navigateTo({
      url: "/pages/businessIntroduction/source",
    })
  },
  showProject() {
    wx.navigateTo({
      url: "/pages/businessIntroduction/project",
    })
  },
  showMessage() {
    wx.navigateTo({
      url: "/pages/businessIntroduction/message",
    })
  },
  showContract() {
    wx.navigateTo({
      url: "/subpkg/pages/test",
    })
  },
  handleContact (e) {
    console.log(e.detail.path)
    console.log(e.detail.query)
}
})